package com.heima.media.controller;

import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "频道管理API")
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    IWmChannelService channelService;

    /**
     * 根据名称模糊查询分页列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "根据名称模糊查询分页列表" ,notes = "author:lqw")
    @ApiImplicitParam(name = "dto" ,value = "查询对象" ,required = true ,dataType = "ChannelDto")
    @PostMapping("/list")
    public PageResponseResult listByName(@RequestBody ChannelDto dto) {
        return channelService.listByName(dto);
    }

    /**
     * 新增频道
     * @param channel
     * @return
     */
    @ApiOperation(value = "新增频道" ,notes = "author:lqw")
    @ApiImplicitParam(name = "channel" ,value = "频道对象" ,required = true ,dataType = "WmChannel")
    @PostMapping
    public ResponseResult saveWmChannel(@RequestBody WmChannel channel){
        return channelService.saveWmChannel(channel);
    }

    /**
     * 修改频道
     * @param dto
     * @return
     */
    @PutMapping
    public ResponseResult updateChannel(@RequestBody WmChannel dto){
       return channelService.updateChannel(dto);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id){
        channelService.removeById(id);
        return ResponseResult.okResult();
    }

    /**
     * 查询频道列表
     * @return
     */
    @GetMapping("channels")
    public ResponseResult<WmChannel> list(){
        List<WmChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
